﻿using System;
using QLNet;
using p = FinPlusAnalytics.QLConvParser;
using u = FinPlusUtility.Utility;

namespace FinPlusAnalytics
{
    public class FixedLegTrade : Trade
    {
        public string Id { get; private set; }
   
        //construct
        public FixedLegTrade(string marketName, string cacheName, string id, string curveName, double nominal, DateTime start, DateTime maturity, 
            double fixedRate, string payRec, string index, string  fixLegFrq, string fixLegConv, string fixLegDayCount, string holidays, bool endOfMonth = false)
        {
            Id = id;
            var market = Markets.Instance.GetMarket(marketName);
            var cache = Caches.Instance.GetCache(cacheName);
            var indx = market.GetIndex(index);
            var calendar = p.Calendar(holidays);
            var type = u.EnumParse<QLNet.FixedLeg.Type>(p.PayRec(payRec));
		
            var schedule = new Schedule(start, maturity, new Period(p.Freq(fixLegFrq)), calendar, p.BizConv(fixLegConv), 
                p.BizConv(fixLegConv), DateGeneration.Rule.Forward, endOfMonth);

            Underlying = new FixedLeg(type, nominal, schedule, fixedRate, p.DayCount(fixLegDayCount));

            cache.Add(id, this, curveName);
        }
    }
}
